package com.property.demo.repository;

import com.property.demo.model.Complaint;
import com.property.demo.model.Owner;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface ComplaintRepository extends JpaRepository<Complaint, Long>, JpaSpecificationExecutor<Complaint> {
    
    List<Complaint> findByStatus(String status);
    
    List<Complaint> findByType(String type);
    
    List<Complaint> findByOwner(Owner owner);
    
    List<Complaint> findByOwnerId(Long ownerId);
    
    List<Complaint> findByTitleContaining(String title);

    @Query("SELECT COUNT(c) FROM Complaint c WHERE c.submitTime >= :start AND c.submitTime <= :end")
    long countBySubmitTimeBetween(@Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
} 